/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.bussines.ejbs;

import cl.bussines.entities.OrdenTrabajo;
import cl.bussines.entities.Rol;
import cl.bussines.entities.RolHasPermisos;
import cl.bussines.vo.Stock;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author Vogel
 */
@Stateless
public class RolHasPermisosFacade extends AbstractFacade<RolHasPermisos> {
    @PersistenceContext(unitName = "TallerStudioPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public RolHasPermisosFacade() {
        super(RolHasPermisos.class);
    }
    
     public List<RolHasPermisos> getPermisosByRol(Rol rol){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("TallerStudioPU");
        EntityManager em2 = emf.createEntityManager();
        String sql = "select r FROM RolHasPermisos r WHERE r.idRol = :rol";
        TypedQuery<RolHasPermisos> query = em2.createQuery(sql, RolHasPermisos.class);
        query.setParameter("rol", rol);
        return query.getResultList();
    }
}
